#include "MyContactListener.h"
#include "TestEntity.h"

void MyContactListener::BeginContact(b2Contact* contact) {

  //check if fixture A was a ball
  void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData();
  if ( bodyUserData )
    static_cast<TestEntity*>( bodyUserData )->startContact();

  //check if fixture B was a ball
  bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData();
  if ( bodyUserData )
    static_cast<TestEntity*>( bodyUserData )->startContact();

}

void MyContactListener::EndContact(b2Contact* contact) {

  //check if fixture A was a ball
  void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData();
  if ( bodyUserData )
    static_cast<TestEntity*>( bodyUserData )->endContact();

  //check if fixture B was a ball
  bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData();
  if ( bodyUserData )
    static_cast<TestEntity*>( bodyUserData )->endContact();

}
